﻿using Server;
using System;
using System.Diagnostics.Contracts;

namespace GetThis_Server.Options
{
    /// <summary>
    /// Application parameters.
    /// </summary>
    internal class ApplicationParameters
    {
        #region Fields

        /// <summary>
        /// The maximum number of lines in the log.
        /// </summary>
        private int m_logLines = Constants.LogLinesDefaultValue;

        /// <summary>
        /// The path of the data file.
        /// </summary>
        private string m_dataPath = Constants.DataPathDefaultValue;

        /// <summary>
        /// The <see cref="T:Server.TcpServer" /> parameters.
        /// </summary>
        private ServerParameters m_serverParameters = new ServerParameters();

        #endregion

        #region Properties

        /// <summary>
        /// The maximum number of lines in the log.
        /// </summary>
        internal int LogLines
        {
            get
            {
                Contract.Ensures(Contract.Result<int>() > 0);

                return m_logLines;
            }
            set
            {
                Contract.Requires<ArgumentOutOfRangeException>(value > 0);

                m_logLines = value;
            }
        }

        /// <summary>
        /// The path of the data file.
        /// </summary>
        internal string DataPath
        {
            get
            {
                Contract.Ensures(!String.IsNullOrWhiteSpace(Contract.Result<string>()));

                return m_dataPath;
            }
            set
            {
                Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(value));

                m_dataPath = value;
            }
        }

        /// <summary>
        /// The <see cref="T:Server.TcpServer" /> parameters.
        /// </summary>
        internal ServerParameters ServerParameters
        {
            get
            {
                Contract.Ensures(Contract.Result<ServerParameters>() != null);

                return m_serverParameters;
            }
            set
            {
                Contract.Requires<ArgumentNullException>(value != null);

                m_serverParameters = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Define the invariant valid state for this class.
        /// </summary>
        [ContractInvariantMethod]
        private void InvariantValidState()
        {
            Contract.Invariant(m_logLines > 0);
            Contract.Invariant(!String.IsNullOrWhiteSpace(m_dataPath));
            Contract.Invariant(m_serverParameters != null);
        }

        #endregion
    }
}
